package gam.n1.ask;

import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;

import java.util.function.Supplier;

public class AskLocation implements Listener, Supplier<Location> {
    private volatile Location a = null;
    @EventHandler
    public void a(PlayerInteractEvent var1){
        if (Asking.isAsking(var1.getPlayer().getUniqueId()) && var1.getAction().equals(Action.LEFT_CLICK_BLOCK)){
            Block var2 = var1.getClickedBlock();
            if (var2 != null){
                Location cB = var2.getLocation();
                if (a == null) a = cB;
            }
            var1.setCancelled(true);
            HandlerList.unregisterAll(this);
        }
    }
    @Override
    public Location get() {
        while (a == null);
        return a;
    }
}
